pkg.dependencies().iter().filter(|d| {
d.name() == dep.name()
}).any(|d| {
-
// If this target is a build command, then we only want build
// dependencies, otherwise we want everything *other than* build
// dependencies.
target.is_example() ||
profile.test;
- is_correct_dep && is_actual_dep
+ // If the dependency is optional, then we're only activating it
+ // if the corresponding feature was activated
+ let activated = !d.is_optional() ||
+ self.resolve.features(pkg.package_id()).map(|f| {
+ f.contains(d.name())
+ }).unwrap_or(false);
+
+ is_correct_dep && is_actual_dep && activated
})
}).filter_map(|pkg| {
pkg.targets().iter().find(|t| t.is_lib()).map(|t| {
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
});
+
+test!(optional_and_dev_dep {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "test"
+ version = "0.1.0"
+ authors = []
+
+ [dependencies]
+ foo = { path = "foo", optional = true }
+ [dev-dependencies]
+ foo = { path = "foo" }
+ "#)
+ .file("src/lib.rs", "")
+ .file("foo/Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
+ "#)
+ .file("foo/src/lib.rs", "");
+
+ assert_that(p.cargo_process("build"),
+ execs().with_status(0).with_stdout(format!("\
+{compiling} test v0.1.0 ([..])
+", compiling = COMPILING)));
+});